<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="stylesheet"  href="/layui/css/layui.css"/>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>扣款操作</title>
</head>
<body>
<script src="/plugins/jquery/jquery-1.10.2.min.js"></script>
<script  src="/layui/layui.js"></script>
<script src="/plugins/js/common.js"></script>
<form class="layui-form" id="saveForm">
	<input type="hidden" name="productId" id="productId" th:value="${param.productId}">
	<br>
<!--   <input type="hidden" id="attachmentId" name="attachmentId">	 -->
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">产品：</label>
	      <div class="layui-input-inline">
	        <input  name="productName" id="productName"  th:value="${product.name}" readonly="readonly" autocomplete="off" class="layui-input">
	      </div>
	    </div>
  </div>	

  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">打款人身份证号：</label>
	      <div class="layui-input-inline">
	        <input  name="paymentIdCode" id="paymentIdCode" onblur="checkIdCode(this.value);" placeholder="打款人身份证号" lay-verify="required" style="width: 260px;" autocomplete="off" class="layui-input">
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">打款人真实姓名：</label>
	      <div class="layui-input-inline">
	        <input  name="paymentRealName"  id="paymentRealName" style="width: 260px;"  lay-verify="required" autocomplete="off" class="layui-input">
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">扣款平均金额：</label>
	      <div class="layui-input-inline">
	        <input  name="averageAmount" placeholder="￥" id="averageAmount" lay-verify="required|number"  autocomplete="off" class="layui-input">
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="saveProductPay">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
<script type="text/javascript">
layui.use(['form', 'layedit','upload'], function(){
	 upload = layui.upload;
	 form = layui.form;
	 form.on('submit(saveProductPay)', function(data){
		if(!checkIdCode($("#paymentIdCode").val())){
			return false;
		} 
		var readyResult = ajaxAction("/productPay/readyDeduction",{productId:$("#productId").val(),notIncludedIdCode:$("#paymentIdCode").val()});
		var total=readyResult.data;
		var totalAmount = ($("#averageAmount").val()*total).toFixed(2);
		var msg = "产品名称：&nbsp;"+$("#productName").val()+"&nbsp;&nbsp;&nbsp;&nbsp;<br><br>";
		msg+="电子凭证扣款总数：&nbsp;"+total+"&nbsp;&nbsp;&nbsp;&nbsp;<br><br>";
		msg+="扣款总金额："+totalAmount;
		layer.confirm(msg, {
	    		  btn: ['确认并提交','取消'] //按钮
	    		}, function(){
	    		  var deductionResult = ajaxAction("/productPay/deduction",$("#saveForm").serialize());
	    		  if(deductionResult.status == 1){
	    			  layer.closeAll('dialog');
	    			  parent.search("扣款成功");
	    			  var index = parent.layer.getFrameIndex(window.name);
	              	  setTimeout(function(){parent.layer.close(index)}, 1000);
	    		  }else{
	    			  layer.alert(deductionResult.returnMsg);
	    		  }
	    		});

	return false;	  
	});
});

function checkIdCode(idCode){
	if(isNull(idCode)){
		return false;
	}
	var result=ajaxAction("/productPay/selectAppUserProductByIdCode",{productId:$("#productId").val(),idCode:idCode});
	if(result.status==2){
		layer.msg(result.returnMsg, {icon: 5});
		return false;
	}
	$("#paymentRealName").val(result.data.applyPeopleName);
	return true;
}


</script>
</body>
</html>